#pragma once
#include <sys/epoll.h>
#include "tinyrpc/base/noncopyable.h"
#include "tinyrpc/base/task.h"

#include <memory>

namespace TinyRPC {

const int ReadEvent = EPOLLIN;
const int WriteEvent =  EPOLLOUT;
const int NoneEvent =  0;

enum EventStatus{
    INTIED,
    ADDED,
    DELETED
};
class AbstractChannel;
class Event {

public:
    Event(int fd, AbstractChannel *ownerChannel);

    void reset(const Event& event);
    void setWriteTask(Task&& writeTask);
    void setReadTask(Task&&);
    void setWriteTask(const Task& writeTask);
    void setReadTask(const Task& readTask);

    void enableReading();
    void enableWriting();
    void enableNone();

    void setRevents(int revent);

    void handleEvent();
    int getFd() const{return m_fd;}
    int getEventOP() const {return m_events;}
    EventStatus getStatus() { return m_status;}
    EventStatus setStatus(EventStatus status) {m_status = status;}
    AbstractChannel * getOwnerChannel() { return m_ownerChannel;};
private:
    AbstractChannel * m_ownerChannel;
    int  m_fd;
    EventStatus m_status;
    int m_events;
    int m_revents;
    Task m_readTask;
    Task m_writeTask;
};

using EventPtr = std::shared_ptr<Event>;
}
